import React, { Component } from 'react';

import ReactDOM from "react-dom";

let geth1 = () => {
  let h1 = document.createElement("h1");
  document.body.append(h1);
  return h1;
}

function withPortal(Zujian) {
  return class Portal extends Component {
    constructor(props) {
      super(props);
      this.el = geth1();
    }
    render() {
      return React.createPortal(<Zujian />, this.el)
    }
  }
}

class Text extends Component {
  render() {
    return <i>哈哈哈</i>
  }
}

const Portal = withPortal(Text);

class App extends Component {

  render() {
    return (
      <div>
        <h1>App 组件</h1>
        <Portal></Portal>
      </div>
    );
  }
}
ReactDOM.render(
  <App />,
  document.getElementById('root')
)
